home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / newmat08.zip / TMT4.CPP < prev    next >
C/C++ Source or Header  |  1995-01-11  |  3KB  |  80 lines

  1.  
  2. //#define WANT_STREAM
  3.  
  4.  
  5. #include "include.h"
  6.  
  7. #include "newmat.h"
  8.  
  9.  
  10. /**************************** test program ******************************/
  11.  
  12. void Print(const Matrix& X);
  13. void Print(const UpperTriangularMatrix& X);
  14. void Print(const DiagonalMatrix& X);
  15. void Print(const SymmetricMatrix& X);
  16. void Print(const LowerTriangularMatrix& X);
  17.  
  18. void trymat4()
  19. {
  20. //   cout << "\nFourth test of Matrix package\n";
  21.    Tracer et("Fourth test of Matrix package");
  22.    Exception::PrintTrace(TRUE);
  23.  
  24.    int i,j;
  25.  
  26.    {
  27.       Tracer et1("Stage 1");
  28.       Matrix M(10,10);
  29.       UpperTriangularMatrix U(10);
  30.       for (i=1;i<=10;i++) for (j=1;j<=10;j++) M(i,j) = 100*i+j;
  31.       U << -M;
  32.       Matrix X1 = M.Rows(2,4);
  33.       Matrix Y1 = U.t().Rows(2,4);
  34.       Matrix X = U; { Print(Matrix(X.Columns(2,4).t()-Y1)); }
  35.       RowVector RV = M.Row(5);
  36.       {
  37.          X.ReDimension(3,10);
  38.          X.Row(1) << M.Row(2); X.Row(2) << M.Row(3); X.Row(3) << M.Row(4);
  39.          Print(Matrix(X-X1));
  40.       }
  41.       {
  42.          UpperTriangularMatrix V = U.SymSubMatrix(3,5);
  43.          Matrix MV = U.SubMatrix(3,5,3,5); { Print(Matrix(MV-V)); }
  44.          Matrix X2 = M.t().Columns(2,4); { Print(Matrix(X2-X1.t())); }
  45.          Matrix Y2 = U.Columns(2,4); { Print(Matrix(Y2-Y1.t())); }
  46.          ColumnVector CV = M.t().Column(5); { Print(ColumnVector(CV-RV.t())); }
  47.          X.ReDimension(10,3); M = M.t();
  48.          X.Column(1) << M.Column(2); X.Column(2) << M.Column(3);
  49.          X.Column(3) << M.Column(4);
  50.          Print(Matrix(X-X2));
  51.       }
  52.    }
  53.  
  54.    {
  55.       Tracer et1("Stage 2");
  56.       Matrix M; Matrix X; M.ReDimension(5,8);
  57.       for (i=1;i<=5;i++) for (j=1;j<=8;j++) M(i,j) = 100*i+j;
  58.       {
  59.          X = M.Columns(5,8); M.Columns(5,8) << M.Columns(1,4);
  60.              M.Columns(1,4) << X;
  61.          X = M.Columns(3,4); M.Columns(3,4) << M.Columns(1,2);
  62.              M.Columns(1,2) << X;
  63.          X = M.Columns(7,8); M.Columns(7,8) << M.Columns(5,6);
  64.              M.Columns(5,6) << X;
  65.       }
  66.       {
  67.          X = M.Column(2); M.Column(2) = M.Column(1); M.Column(1) = X;
  68.          X = M.Column(4); M.Column(4) = M.Column(3); M.Column(3) = X;
  69.          X = M.Column(6); M.Column(6) = M.Column(5); M.Column(5) = X;
  70.          X = M.Column(8); M.Column(8) = M.Column(7); M.Column(7) = X;
  71.          X.ReDimension(5,8);
  72.       }
  73.       for (i=1;i<=5;i++) for (j=1;j<=8;j++) X(i,9-j) = 100*i+j;
  74.       Print(Matrix(X-M));
  75.    }
  76.  
  77. //   cout << "\nEnd of fourth test\n";
  78. }
  79.  
  80.